package gui.user.model;

import dao.ProductDao;
import entity.Product;

import javax.swing.table.DefaultTableModel;
import java.util.List;

public class UserProductModel extends DefaultTableModel {
    ProductDao productDao = new ProductDao();
    String[] tableHeaders = new String[]{"商品名称","售价","库存"};//商品信息表头
    List productList = null;
    String[][] productData = null;
    public UserProductModel(String categoryId) throws Exception {
        productList = productDao.getAppointProducts(categoryId);
        productData = new String[productList.size()][tableHeaders.length];
        for (int i = 0; i < productList.size(); i++) {
            Product product = (Product)productList.get(i);
            productData[i][0] = product.getProductName();
            productData[i][1] = String.valueOf(product.getSalePrice());
            productData[i][2] = String.valueOf(product.getStockQuantity());
        }
        this.setDataVector(productData,tableHeaders);
    }
}
